package com.miplus.ccrm.core.controller;

import com.miplus.ccrm.common.R;
import com.miplus.ccrm.core.controller.vo.file.UploadResVo;
import com.miplus.ccrm.core.service.FileService;
import com.miplus.ccrm.core.service.xsky.XSkyService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 2-6.文件管理服务接口
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/file")
public class FileController {
    @Resource
    private FileService fileService;

    @Resource
    private XSkyService xSkyService;

    /**
     * 上载附件文件
     */

    @RequestMapping(value = "upload", method = RequestMethod.POST)
    public R<UploadResVo> upload(@RequestParam("file") MultipartFile file) {
        return R.Success(fileService.doUpload(file));
    }

    /**
     * 下载附件文件
     */
    @RequestMapping(value = "download", method = RequestMethod.GET)
    public R download(String skyid, HttpServletResponse response) {
        return R.Success(fileService.DownloadLocalFile(skyid,response));
    }

    /**
     * 调听录音
     */
    @RequestMapping(value = "play", method = RequestMethod.GET)
    public R play(String skyid, HttpServletResponse response) {
        //xSkyService.OnPlayRecord(skyid,response);
        xSkyService.OnPlayFile(skyid, response);
        return R.Success();
    }
}
